home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / Portable Patmos / usr / include / netccitt / hdlc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-08  |  4.8 KB  |  163 lines  |  [TEXT/R*ch]

  1. /*-
  2.  * Copyright (c) University of British Columbia, 1984
  3.  * Copyright (c) 1991 The Regents of the University of California.
  4.  * All rights reserved.
  5.  *
  6.  * This code is derived from software contributed to Berkeley by the
  7.  * Laboratory for Computation Vision and the Computer Science Department
  8.  * of the University of British Columbia.
  9.  *
  10.  * Redistribution and use in source and binary forms, with or without
  11.  * modification, are permitted provided that the following conditions
  12.  * are met:
  13.  * 1. Redistributions of source code must retain the above copyright
  14.  *    notice, this list of conditions and the following disclaimer.
  15.  * 2. Redistributions in binary form must reproduce the above copyright
  16.  *    notice, this list of conditions and the following disclaimer in the
  17.  *    documentation and/or other materials provided with the distribution.
  18.  * 3. All advertising materials mentioning features or use of this software
  19.  *    must display the following acknowledgement:
  20.  *    This product includes software developed by the University of
  21.  *    California, Berkeley and its contributors.
  22.  * 4. Neither the name of the University nor the names of its contributors
  23.  *    may be used to endorse or promote products derived from this software
  24.  *    without specific prior written permission.
  25.  *
  26.  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  27.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  28.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  29.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  30.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  34.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  35.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  36.  * SUCH DAMAGE.
  37.  *
  38.  *    from: @(#)hdlc.h    7.4 (Berkeley) 5/6/91
  39.  *    $Id: hdlc.h,v 1.3 1993/05/20 04:12:11 cgd Exp $
  40.  */
  41.  
  42. #ifndef _NETCCITT_HDLC_H_
  43. #define _NETCCITT_HDLC_H_
  44.  
  45. #ifndef ORDER4
  46. #define FALSE   0
  47. #define TRUE    1
  48. typedef u_char octet;
  49. typedef char    bool;
  50.  
  51. /*
  52.  *  HDLC Packet format definitions
  53.  *  This will eventually have to be rewritten without reference
  54.  *  to bit fields, to be compliant with ANSI C and alignment safe.
  55.  */
  56.  
  57. #if BYTE_ORDER == BIG_ENDIAN
  58. #define ORDER4(a, b, c, d) a , b , c , d
  59. #define ORDER5(a, b, c, d, e) a , b , c , d , e
  60. #endif
  61.  
  62. #if BYTE_ORDER == LITTLE_ENDIAN
  63. #define ORDER4(a, b, c, d) d , c , b , a
  64. #define ORDER5(a, b, c, d, e) e , d , c , b , a
  65. #endif
  66. #endif
  67.  
  68. #define MAX_INFO_LEN    4096+3+4
  69. #define ADDRESS_A       3    /* B'00000011' */
  70. #define ADDRESS_B       1    /* B'00000001' */
  71.  
  72. struct Hdlc_iframe {
  73.     octet    address;
  74.     octet    ORDER4(nr:3, pf:1, ns:3, hdlc_0:1);
  75.     octet    i_field[MAX_INFO_LEN];
  76. };
  77.  
  78. struct Hdlc_sframe {
  79.     octet    address;
  80.     octet    ORDER4(nr:3, pf:1, s2:2, hdlc_01:2);
  81. };
  82.  
  83. struct    Hdlc_uframe {
  84.     octet    address;
  85.     octet    ORDER4(m3:3, pf:1, m2:2, hdlc_11:2);
  86. };
  87.  
  88. struct    Frmr_frame {
  89.     octet    address;
  90.     octet    control;
  91.     octet    frmr_control;
  92.     octet    ORDER4(frmr_nr:3, frmr_f1_0:1, frmr_ns:3, frmr_f2_0:1);
  93.     octet    ORDER5(frmr_0000:4, frmr_z:1, frmr_y:1, frmr_x:1, frmr_w:1);
  94. };
  95.  
  96. #define HDHEADERLN    2
  97. #define MINFRLN        2        /* Minimum frame length. */
  98.  
  99. struct    Hdlc_frame {
  100.     octet    address;
  101.     octet    control;
  102.     octet    info[3];    /* min for FRMR */
  103. };
  104.  
  105. #define SABM_CONTROL 057    /* B'00101111' */
  106. #define UA_CONTROL   0143    /* B'01100011' */
  107. #define DISC_CONTROL 0103    /* B'01000011' */
  108. #define DM_CONTROL   017    /* B'00001111' */
  109. #define FRMR_CONTROL 0207    /* B'10000111' */
  110. #define RR_CONTROL   01        /* B'00000001' */
  111. #define RNR_CONTROL  05        /* B'00000101' */
  112. #define REJ_CONTROL  011    /* B'00001001' */
  113.  
  114. #define POLLOFF  0
  115. #define POLLON   1
  116.  
  117. /* Define Link State constants. */
  118.  
  119. #define INIT        0
  120. #define DM_SENT        1
  121. #define SABM_SENT    2
  122. #define ABM        3
  123. #define WAIT_SABM    4
  124. #define WAIT_UA        5
  125. #define DISC_SENT    6
  126. #define DISCONNECTED    7
  127. #define MAXSTATE    8
  128.  
  129. /* The following constants are used in a switch statement to process
  130.    frames read from the communications line. */
  131.  
  132. #define SABM     0 * MAXSTATE
  133. #define DM       1 * MAXSTATE
  134. #define DISC     2 * MAXSTATE
  135. #define UA       3 * MAXSTATE
  136. #define FRMR     4 * MAXSTATE
  137. #define RR       5 * MAXSTATE
  138. #define RNR      6 * MAXSTATE
  139. #define REJ      7 * MAXSTATE
  140. #define IFRAME   8 * MAXSTATE
  141. #define ILLEGAL  9 * MAXSTATE
  142.  
  143. #define T1    (3 * PR_SLOWHZ)        /*  IFRAME TIMEOUT - 3 seconds */
  144. #define T3    (T1 / 2)        /*  RR generate timeout - 1.5 seconds */
  145. #define N2    10
  146. #define MODULUS 8
  147. #define MAX_WINDOW_SIZE 7
  148.  
  149. #define Z  0
  150. #define Y  1
  151. #define X  2
  152. #define W  3
  153. #define A  4
  154.  
  155. #define TX 0
  156. #define RX 1
  157.  
  158. bool    range_check ();
  159. bool    valid_nr ();
  160. struct    mbuf *hd_remove ();
  161.  
  162. #endif /* !_NETCCITT_HDLC_H_ */
  163.